{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c498e2f4-6893-4707-b9ae-2bb626b92e12",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('aaa.txt', \"r\", encoding='utf-8') as f:\n",
    "        txt = f.readlines() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4999d979-5fdb-4738-9bdc-f677643d7394",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('bbb.txt', \"r\", encoding='utf-8') as f:\n",
    "        txt2 = f.readlines() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4bbc1835-fc56-43ac-a2c4-5f227eadc544",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "89 <class 'list'>\n",
      "87 <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "print(len(txt), type(txt))\n",
    "print(len(txt2), type(txt2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d4a1360c-5615-478c-8bef-05d5bf37b851",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aaa 79\n",
      "bbb 79\n"
     ]
    }
   ],
   "source": [
    "print('aaa', len([''.join(i.split()) for i in txt if len(''.join(i.split())) > 1]))\n",
    "print('bbb', len([''.join(i.split()) for i in txt2 if len(''.join(i.split())) > 1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16ced5aa-a401-46a4-9fc8-8366a8481e56",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c04c22fd-4d93-4852-b467-e8b634195078",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "24b27191-400e-443f-8f32-b31275b6ab15",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9f521e47-c9dd-4bbb-bddb-18337502ca89",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "\"job\":{\n",
      "\"content\":[\n",
      "{\n",
      "\"reader\":{\n",
      "\"name\":\"mysqlreader\",\n",
      "\"parameter\":{\n",
      "\"column\":['*'],\n",
      "\"connection\":[\n",
      "{\n"
     ]
    }
   ],
   "source": [
    "for i in txt2[:10]:\n",
    "    print(''.join(i.split()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "aefe17df-4e60-49da-9fa4-80d30aad0c8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "\"column\":[\"*\"],\n",
      "\"column\":['*'],\n",
      "12\n",
      "\"table\":[\"cust_info\"]\n",
      "\"table\":['cust_info']\n",
      "45\n",
      "\"defaultFS\":\"hdfs://localhost\",\n",
      "\"defaultFS\":\"hdfs://localhost:8020\",\n"
     ]
    }
   ],
   "source": [
    "for i in range(len(txt)):\n",
    "    if ''.join(txt[i].split()) != ''.join(txt2[i].split()):\n",
    "        print(i+1)\n",
    "        print(''.join(txt[i].split()))\n",
    "        print(''.join(txt2[i].split()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8409e3fe-ccc7-42e2-b350-2562a852ffcd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "45\n",
      "\"defaultFS\":\"hdfs://localhost\",\n",
      "\"defaultFS\":\"hdfs://localhost:8020\",\n"
     ]
    }
   ],
   "source": [
    "for i in range(len(txt)):\n",
    "    if ''.join(txt[i].split()).replace(\"'\", '\"') != ''.join(txt2[i].split()).replace(\"'\", '\"'):\n",
    "        print(i+1)\n",
    "        print(''.join(txt[i].split()))\n",
    "        print(''.join(txt2[i].split()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e53eed5-cebb-49ba-8bfa-5174fa49820e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "013c1884-162f-41a4-acd9-8cd6ca2231e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def find_diff(a, b, md=1):\n",
    "    with open(a, \"r\", encoding='utf-8') as f:\n",
    "        txt = f.readlines() \n",
    "    with open(b, \"r\", encoding='utf-8') as f:\n",
    "        txt2 = f.readlines()\n",
    "    if md:\n",
    "        for i in range(len(txt)):\n",
    "            if ''.join(txt[i].split()) != ''.join(txt2[i].split()):\n",
    "                print(i+1)\n",
    "                print(''.join(txt[i].split()))\n",
    "                print(''.join(txt2[i].split()))\n",
    "    else:\n",
    "        for i in range(len(txt)):\n",
    "            if ''.join(txt[i].split()).replace(\"'\", '\"') != ''.join(txt2[i].split()).replace(\"'\", '\"'):\n",
    "                print(i+1)\n",
    "                print(''.join(txt[i].split()))\n",
    "                print(''.join(txt2[i].split()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b7044bed-42ae-4004-84b0-45c0502c2a80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n",
      "sum(if(overduedays>90,balance,0)),\n",
      "sum(if(overduedays>90,balance,0))sum90,\n",
      "23\n",
      "fromfdm.fdm_cust_debt_i;\n",
      "fromfdm.fdm_cust_debt_i\n"
     ]
    }
   ],
   "source": [
    "find_diff('aaa.txt', 'bbb.txt', 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9020f8f5-90c9-4294-bab9-dc258171bc46",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "e6479852-0e2e-4a1f-9793-4771d3046cd3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def print_diff(lst, lst2, md=1):\n",
    "    if md == 1:\n",
    "        for i in range(len(lst)):\n",
    "            if lst[i] != lst2[i]:\n",
    "                print(i+1)\n",
    "                print(lst[i])\n",
    "                print(lst2[i])\n",
    "    else:\n",
    "        for i in range(len(lst)):\n",
    "            if lst[i].replace(\"'\", '\"') != lst2[i].replace(\"'\", '\"'):\n",
    "                print(i+1)\n",
    "                print(lst[i])\n",
    "                print(lst2[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "7096bac0-8869-4c12-9959-602b063a7e1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def find_diff2(a, b, md=1):\n",
    "    with open(a, \"r\", encoding='utf-8') as f:\n",
    "        txt = f.readlines() \n",
    "    with open(b, \"r\", encoding='utf-8') as f:\n",
    "        txt2 = f.readlines()\n",
    "    txt = [''.join(i.split()) for i in txt if len(''.join(i.split())) > 0]\n",
    "    txt2 = [''.join(i.split()) for i in txt2 if len(''.join(i.split())) > 0]\n",
    "    print('aaa净长：', len(txt))\n",
    "    print('bbb净长：', len(txt2))\n",
    "    if len(txt) == len(txt2):\n",
    "        if md:\n",
    "            print_diff(txt, txt2)\n",
    "        else:\n",
    "            print_diff(txt, txt2, 0)\n",
    "    else:\n",
    "        print('两个txt文本在删除空格行之后长度仍不一致！！！')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "515e1038-769b-4513-9dd5-4f9557303d45",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aaa净长： 80\n",
      "bbb净长： 80\n",
      "9\n",
      "--1，核额流水表\n",
      "--1.核额流水表\n",
      "79\n",
      "whereupdate_time='$dt5';\n",
      "whereupdate_time=\"$dt5\";\n"
     ]
    }
   ],
   "source": [
    "find_diff2('aaa.txt', 'bbb.txt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecfec39b-3a4b-4dfb-966d-dddaf6cd1cf2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e35042b-42b2-408a-b078-c43c928f3549",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e871635-93ab-4b71-9553-594bfe0e0e72",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee539b52-dfb0-4a15-af12-0967bfc1b421",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "703865ea-5553-45e6-9fb1-e040d6b45765",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f777e8e3-5bf2-4ea5-8653-17004a3f62b0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
